/*
 *  engine.h
 */

#ifndef ENGINE_H
#define ENGINE_H

#include <string>
#include "../../common/src/runnable.h"
#include "../../common/src/synchro_list.h"
#include "../../model/src/campaign.h"
#include "../../model/src/game.h"
#include "../../model/src/player.h"

// Cross reference class forward declaration
class ServerApp;

class Engine : public Runnable {
public:
    Engine(ServerApp* app);
    ~Engine();
    void run();
    void processMessages();
    void createGame(Session* session, Message* msg);
    void abortGame(Session* session, Message* msg);
    void joinGame(Session* session, Message* msg);
    void startGame(Session* session);
    void sendGameList(Session* session);
    void sendCampaignList(Session* session);
    void disconnect(Session* session);
private:
    static int player_gen_id;
    static int game_gen_id;
    static int nextPlayerID();
    static int nextGameID();
    ServerApp* app;
    SynchroList<Game*> games;
    SynchroList<Player*> players;
    Session* getSession(std::string sessionID);
    Game* getGame(int gameID);
    Game* getGame(Player* player, bool is_owner);
    Player* getPlayer(std::string sessionID);
    Campaign* getCampaign(int campaignID);
};

#endif  //ENGINE_H

//{+}

